package com.wooophone.common.interceptor;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

@SuppressWarnings("serial")
public class LoggerInterceptor extends AbstractInterceptor {
	static int count = 0;
	Logger logger = Logger.getLogger(this.getClass());

	public synchronized int addCount() {
		return ++count;
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		String result = null;
		try {

			int num = addCount();
			String name = invocation.getAction().getClass().getSimpleName();
			logger.info("Action Excute Begin  " + num + ":" + name);
			long start = System.currentTimeMillis();
			result = invocation.invoke();
			long end = System.currentTimeMillis();
			logger.info("Action Excute Finished  " + num + ":" + name
					+ "     result:" + result + "	 run time: " + (end - start)
					+ " milliseconds");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
